{include file='common/_meta' /}
<style>
    .vsmscode {
        z-index: 19891010;
        position: fixed;
        top: 0px;
        bottom: 0px;
        left: 0px;
        right: 0px;
        background: rgba(85, 85, 85, 0.8);
        overflow: hidden;
    }
    .vsmscode > div {
        width: 300px;
        margin: 80px auto 0px;
        background: #fff;
        padding: 10px;
        border-radius: 5px;
    }
    input::-webkit-outer-spin-button,
    input::-webkit-inner-spin-button {
        -webkit-appearance: none;
    }
    input[type="number"]{
        -moz-appearance: textfield;
    }

</style>
<body>
<div class="container">
	<div class="layui-row">
        <div class="layui-col-md12 breadcrumb">
    		<span class="layui-breadcrumb">
                <a><cite>审核管理</cite></a>
    			<a><cite>短信审核</cite></a>
    		</span>
        </div>
    </div>

    <div class="layui-row">

    	<form class="layui-form" action="" lay-filter="FORM_FILTER" style="padding-top: 15px;" id="search-form">
            <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">发送类型：</label>
                    <div class="layui-input-block">
                        <select name="phone_type" id="phone_type" lay-search>
                            <option value="">全部</option>
                            <option value="0">群发</option>
                            <option value="1">单发</option>
                        </select>
                    </div>
                </div>
            </div>
            {if condition="session('user_type') == 'admin' or session('channel_level') eq '1' "}

            <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">渠道：</label>
                    <div class="layui-input-block">
                        <select name="cid" id="cid" lay-search>
                            {volist name='chas' id='c'}
                            <option value="{$c.channel_id}"> {$c.company_name}({$c.channel_id})</option>
                            {/volist}
                        </select>
                    </div>
                </div>
            </div>

            {/if}
<!--             <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">状态：</label>
                    <div class="layui-input-block">
                        <select name="state" id="state" lay-search>
                            <option value="0">待审核</option>
                            <option value="">全部</option>
                            <option value="1">通过</option>
                            <option value="2">失败</option>
                        </select>
                    </div>
                </div>
            </div> -->
            <div class="layui-col-sm6 layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">日期选择：</label>
                    <div class="layui-input-block">
                        <input type="text" name="st" autocomplete="off" placeholder="" class="layui-input" id="st">
                    </div>
                </div>
            </div>

            <div class="layui-col-sm6 layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">开始时间：</label>
                    <div class="layui-input-block">
                        <input type="text" name="create_time" autocomplete="off" placeholder="" class="layui-input" id="create_time">
                    </div>
                </div>
            </div>

            <div class="layui-col-sm6 layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">结束时间：</label>
                    <div class="layui-input-block">
                        <input type="text" name="end_time" autocomplete="off" placeholder="" class="layui-input" id="end_time">
                    </div>
                </div>
            </div>

            <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">运营商：</label>
                    <div class="layui-input-block">
                        <select name="isp_host" id="isp_host" lay-search>
                            <option value="">全部</option>
                            <option value="10086">移动</option>
                            <option value="10000">电信</option>
                            <option value="10010">联通</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">通道：</label>
                    <div class="layui-input-block">
                        <select name="platId" id="platId" lay-search>
                            <option value="">全部</option>
                            {volist name='plats' id='p'}
                            <option value="{$p.plat_id}"> {$p.platfrom}({$p.plat_id})</option>
                            {/volist}
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">手机号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="phone" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

<!--             <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">订单号：</label>
                    <div class="layui-input-block">
                        <input type="text" placeholder="渠道订单号" name="channel_order_id" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div> -->
            <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">短信内容：</label>
                    <div class="layui-input-block">
                        <input type="text" name="send_text" autocomplete="off" placeholder="模糊查询" class="layui-input">
                    </div>
                </div>
            </div>
    		<div class="layui-col-sm4">
				<div class="layui-input-block">
			      	<button class="layui-btn custom-sm-fluid" id="search" lay-submit lay-filter="custom-search">搜索</button>
			    </div>
    		</div>

    	</form>

    </div>
    <!-- 审核 -->
    <div id="vsmscode" class="vsmscode layui-hide">
        <div class="layui-form layui-form-pane">
            <!-- <form class="layui-form layui-form-pane" action="" lay-filter="" id="form-article12"> -->
                <div class="layui-col-sm12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">审核描述</label>
                        <div class="layui-input-block">
                            <textarea name="desc" id="desc" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">审核状态</label>
                        <div class="layui-input-block">
                            <select name="status" id="status" lay-search>
                                <option value="1">通过</option>
                                <option value="2">失败</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-row">
                    <div class="layui-form-item">
                        <div class="layui-col-xs6">
                            <button class="layui-btn layui-btn-fluid layui-btn-primary" id="formDemo6"> 取消 </button>
                        </div>
                        <div class="layui-col-xs6">
                            <button class="layui-btn layui-btn-fluid" id="formDemo5"> 提交 </button>
                        </div>
                    </div>
                </div>

            <!-- </form> -->
        </div>
    </div>

    <!-- 批量审核 -->
    <div id="batchReview" class="vsmscode layui-hide">
        <div class="layui-form layui-form-pane">
                <div class="layui-col-sm12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">审核描述</label>
                        <div class="layui-input-block">
                            <textarea name="batchDesc" id="batchDesc" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">审核条数</label>
                        <div class="layui-input-block">
                            <input type="number" name="batchNumber" id="batchNumber" value="50" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>

                <div class="layui-col-sm12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">审核状态</label>
                        <div class="layui-input-block">
                            <select name="batchStatus" id="batchStatus" lay-search>
                                <option value="1">通过</option>
                                <option value="2">失败</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-row">
                    <div class="layui-form-item">
                        <div class="layui-col-xs6">
                            <button class="layui-btn layui-btn-fluid layui-btn-primary" id="closeBatch"> 取消 </button>
                        </div>
                        <div class="layui-col-xs6">
                            <button class="layui-btn layui-btn-fluid" id="batchSubmission"> 提交 </button>
                        </div>
                    </div>
                </div>
        </div>
    </div>
	<div class="layui-col-md12">

		<table class="layui-hide" id="initdate" lay-filter="datatable"></table>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
<!--                 <button class="layui-btn layui-btn-sm" lay-event="add">短信报备</button>
                <button class="layui-btn layui-btn-sm" lay-event="import">批量短信报备</button> -->
                <button class="layui-btn layui-bg-orange layui-btn-sm" lay-event="approved">审核</button>
                <button class="layui-btn layui-btn-sm" lay-event="batchReview">批量审核</button>
            </div>
        </script>

        <script type="text/html" id="barDemo">
          	<a class="layui-btn layui-btn-xs" lay-event="review"><i class="layui-icon layui-icon-edit"></i></a>
        </script>

	</div>

    <input type="hidden" id="selectPhoneType" value="{$requests['phone_type']}"/>
    <input type="hidden" id="selectCid" value="{$requests['cid']}"/>
    <input type="hidden" id="selectSt" value="{$requests['st']}"/>
    <input type="hidden" id="selectCreateTime" value="{$requests['create_time']}"/>
    <input type="hidden" id="selectEndTime" value="{$requests['end_time']}"/>
    <input type="hidden" id="selectIsp" value="{$requests['isp_host']}"/>
    <input type="hidden" id="selectPhone" value="{$requests['phone']}"/>
    <input type="hidden" id="selectPlatId" value="{$requests['platId']}"/>
    <input type="hidden" id="selectSendText" value="{$requests['send_text']}"/>

</div>
{include file="common/_footer"}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
var checkStatus;
layui.use(['table','laydate'], function() {

	var table = layui.table;
	var layer = layui.layer;
	var form  = layui.form;
    var laydate = layui.laydate;

    form.val("FORM_FILTER", {
        "cid": "{$requests.cid}",
        "st":"{$requests.st}"
    })

    //绑定时间插件
    laydate.render({
        elem: '#st'
        ,type: 'date'
    });

    //绑定时间插件
    laydate.render({
        elem: '#create_time'
        ,type: 'time'
        ,value: '{$requests.create_time}'
    });

    laydate.render({
        elem: '#end_time'
        ,type: 'time'
        ,value: '{$requests.end_time}'
    });

    var tableIns = table.render({
        id: 'datatable'
        ,elem: '#initdate'
        ,url:'{:url('SmsReview/index')}'
        ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        ,toolbar: '#toolbarDemo'//默认工具栏
        ,defaultToolbar: []
        ,data:[]
        ,method:'get'//请求方式
        ,where: {api: 1,st:$('#st').val(),cid:$('#cid').val(),create_time:$('#selectCreateTime').val(),end_time:$('#selectEndTime').val()}
        ,page:true//开启分页
        ,limit:15//每页记录数
        ,limits: [15,20,30,40,50,60,70,80,90]
        ,cols: [[
            {type:'checkbox', title: '选择'}
            ,{field:'status', title: '状态', align: 'center'}
            ,{field:'company_name', title: '渠道',align: 'center'}
            ,{field:'channel_order_id', title: '渠道订单号',align: 'center'}
            ,{field:'send_text', title: '短信内容',align: 'center'}
            ,{field:'submit_type', title: '提交类型',align: 'center'}
            ,{field:'phone_size', title: '号码',align: 'center'}
            ,{field:'phone_type', title: '发送类型',align: 'center'}
            ,{field:'create_time', title: '创建时间', minWidth: 175,align: 'center'}
            ,{field:'plat', title: '通道',align: 'center'}
            ,{field:'result', title: '处理结果',align: 'center'}
            ,{field:'review_time', title: '审核时间',align: 'center'}
            // ,{field:'desc', title: '描述',align: 'center'}
            // ,{field:'username', title: '操作人员',align: 'center'}
            // ,{field:'desc', title: '描述',align: 'center'}
            ,{fixed:'right', title: '操作', toolbar: '#barDemo', width: 100, unresize: true}
        ]]
    });

    //监听头工具栏事件
    table.on('toolbar(datatable)', function(obj){

        switch(obj.event) {
            //批量
            case 'batchReview':
                if($('#selectPhoneType').val() == ''){
                    layer.msg('请选择发送类型搜索后再审核!', {icon: 5,time:2000});
                    return false;
                }
                $('#batchReview').removeClass('layui-hide');
                break;
            case 'approved':
                // console.log($('#selectSt').val());
                if($('#selectPhoneType').val() == ''){
                    layer.msg('请选择发送类型搜索后再审核!', {icon: 5,time:2000});
                    return false;
                }
                checkStatus = table.checkStatus('datatable'); //idTest 即为基础参数 id 对应的值
                if(checkStatus.data.length <= 0 )
                {
                    layer.msg('选择一行!', {icon: 5,time:2000});
                    return false;
                }
                $('#vsmscode').removeClass('layui-hide');

                break;
        };
    });

    //监听工具条
  	table.on('tool(datatable)', function(obj) {

        var data = obj.data;

        switch(obj.event) {

            case 'review':
                layer.open({
                        type: 2,
                        title: '审核',
                        area: iSarea(),
                        scrollbar: false,
                        offset: 'r',
                        anim: 2,
                        shadeClose: true,
                        isOutAnim: false,
                        content: '{:url('reviewsms')}' + '?id=' + data.id + '&st=' + $('#selectSt').val(),
                        end: function () {
                            tableIns.reload();
                            $(window).resize();
                        }
                    });
                break;
        };

    });

  	// 监听搜索事件
    form.on('submit(custom-search)', function(data) {

      	tableIns.reload({
            url:'{:url('SmsReview/index')}'
        	,where: {phone_type: data.field.phone_type ,api: 1,cid: data.field.cid,st:data.field.st,create_time:data.field.create_time,end_time:data.field.end_time,isp_host:data.field.isp_host,phone:data.field.phone,send_text:data.field.send_text,platId:data.field.platId}
        	,page: {curr: 1}
      	});
        $('#selectPhoneType').val(data.field.phone_type);
        $('#selectCid').val(data.field.cid);
        $('#selectSt').val(data.field.st);
        $('#selectCreateTime').val(data.field.create_time);
        $('#selectEndTime').val(data.field.end_time);
        $('#selectIsp').val(data.field.isp_host);
        $('#selectPhone').val(data.field.phone);
        $('#selectPlatId').val(data.field.platId);
        $('#selectSendText').val(data.field.send_text);

        $(window).resize()

      	return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
});

function tableInsReload(api){
    var tr = $("#search-form").serializeArray().reduce(function(result, item){
        result[item.name] = item.value;
        return result;
        }, {}
    )

    tr.api = api;

    return tr;
}

$('#formDemo6').click(function(event) {
    $('#vsmscode').addClass('layui-hide');
    return false;
});

$('#formDemo5').click(function(event) {
    // layer.confirm('您确认要通过审核吗？', function(index) {

        $('#vsmscode').addClass('layui-hide');
        var idArr = [];

        for(var i in checkStatus.data){

            idArr[i] = checkStatus['data'][i]['id']
        }

        idArr = JSON.stringify(idArr)

        var load = layer.load();
        $.post('{:url('SmsReview/review')}',{'reviewId':idArr,'desc':$('#desc').val(),'status':$('#status').val(),'st':$('#selectSt').val(),'cid':$('#selectCid').val(),'phone_type':$('#selectPhoneType').val()},function(data) {

            layer.close(load);

            if(data.code == 200) {

                layer.msg(data.msg, {icon:1,time:1000}, function() {
                    // tableIns.reload({
                    //     where: tableInsReload(1)
                    //     ,page: {curr: 1 }
                    // });
                    $('#search').click();
                });

                return false;

            } else {

                layer.msg(data.msg, {icon: 5,time:2000});
            }
        });
    // });
});

$('#closeBatch').click(function(event) {
    $('#batchReview').addClass('layui-hide');
    return false;
});
//批量审核
$('#batchSubmission').click(function(event) {
    // layer.confirm('您确认要通过审核吗？', function(index) {

        $('#batchReview').addClass('layui-hide');
        // var load = layer.load();
        if ($('#batchNumber').val() > 50000) {
            // layer.close(load);
            layer.msg('批量数据最大5W条', {icon: 5,time:2000});
            return false;
        }
        // $.post('{:url('SmsReview/batchreview')}',{'desc':$('#batchDesc').val(),'status':$('#batchStatus').val(),'number':$('#batchNumber').val(),'st':$('#selectSt').val(),'cid':$('#selectCid').val(),'phone_type':$('#selectPhoneType').val(),'create_time':$('#selectCreateTime').val(),'end_time':$('#selectEndTime').val(),'isp':$('#selectIsp').val(),'phone':$('#selectPhone').val(),'platId':$('#selectPlatId').val(),'send_text':$('#selectSendText').val()},function(data) {

        //     layer.close(load);

        //     if(data.code == 200) {

        //         layer.msg(data.msg, {icon:1,time:1000}, function() {
        //             // tableIns.reload({
        //             //     where: tableInsReload(1)
        //             //     ,page: {curr: 1 }
        //             // });
        //             $('#search').click();
        //         });

        //         return false;

        //     } else {

        //         layer.msg(data.msg, {icon: 5,time:2000});
        //     }
        // });
        $.ajax({
            type : "POST",
            url  : "{:url('SmsReview/batchreview')}",
            data : {'desc':$('#batchDesc').val(),'status':$('#batchStatus').val(),'number':$('#batchNumber').val(),'st':$('#selectSt').val(),'cid':$('#selectCid').val(),'phone_type':$('#selectPhoneType').val(),'create_time':$('#selectCreateTime').val(),'end_time':$('#selectEndTime').val(),'isp':$('#selectIsp').val(),'phone':$('#selectPhone').val(),'platId':$('#selectPlatId').val(),'send_text':$('#selectSendText').val()},
            beforeSend: function() {

                load = layer.load();
            },
            success : function(data) {

                if(data.code == 200) {
                    layer.msg(data.msg, {icon:1,time:1000}, function() {
                        // tableIns.reload({
                        //     where: tableInsReload(1)
                        //     ,page: {curr: 1 }
                        // });
                        $('#search').click();
                    });

                    return false;

                } else {

                    layer.msg(data.msg, {icon: 5,time:2000});
                }
            },
            error : function(e) {

                layer.msg('处理失败，', {icon: 5, time: 3000});
            },
            complete: function() {

                layer.close(load);
            }
        });
    // });
});
function open_window(title, url, arg, w, h) {

    w = w || '600';
    h = h || '300';

    var index = layer.open({
        type: 2,
        title: title,
        content: url+arg,
        area:[w+'px',h+'px'],
    });
    layer.full(index);
}

function iSarea() {

    return document.body.scrollWidth > 768 ? ['50%', '100%'] : ['100%', '100%'];
}

</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
